package com.zwh.modbus.modbus4j.enums;

/**
 * @author:Sam
 *
 * @create:2019-11-22 14:16
 **/
public enum StatusCode {
    /**
     * 0-1000：为保留系统状态码
     * 1000-6999：对应http状态码前缀
     *
     * 7000-9999应用级状态码
     * 70**：系统管理服务
     * 71**：设备管理服务
     * 73**：能力编排管理服务
     * ....
     */
    FAILURE(-1, "操作失败"),
    SUCCESS(0, "操作成功"),


    /**
     * from strutsmsg
     */
    PARAMER_ERROR(1,"参数"),
    NOT_USER(2,"not user"),
    SHRIO_EXECUTE_LOGIN_ERROR(3,"shiro执行登录错误"),
    RSA_VERIFY_FAIL(4,"RSA verify fail"),
    RSA_CREATE_FAIL(5,"RSA key create fail"),
    REDIS_SET_FAIL(6,"redis set fail"),
    RESP_HEAD_CONFIG_FAIL(7,"response set header config fail"),
    CREATE_TOKEN_FAIL(8,"create token fail"),
    IS_NOT_USER(9,"用户不存在"),
    IS_NOT_PASSWD_OLD(10,"新旧密码不能相同"),
    IS_NOT_PASSWD(11,"旧密码验证失败"),
    IS_PASSWD(12,"密码长度异常"),
    IS_OPERATOR(13,"功能权限编码已存在，请更换新的功能权限编码"),
    MENU_NAME_EXIST_CODE(14,"菜单名称已存在"),
    ORG_NAME_EXIST_CODE(15,"部门名称已存在" ),
    POST_NAME_EXIST_CODE(16,"岗位名称已存在"),
    PARENT_STATUS_NOT_USE(17,"父级部门未启用"),
    IS_USER(22,"用户已存在"),
    IS_REQUIRED(23,"参数不可为空"),
    IS_JSON_CONTENT_TYPE(24,"请求格式必须为：application/json："),
    IS_JSON_OBJECT(25,"json解析异常"),
    EUREKA(26,"Eureka异常"),
    IS_TOKEN(27,"token获取失败"),
    IS_NOT_USERSESSION(28,"token获取用户id失败"),
    USER_EXPIRED(29,"user expired"),
    USER_PASSWORD_ERROR(30,"用户密码错误"),
    USER_IS_LOCK(31,"用户已锁定，请稍后重试"),
    LICENSE_FAIL(32,"license异常"),
    ROLE_NAME_EXIST_CODE(33,"新增数据失败：角色名称已存在"),


    INVALID_REQUEST(201, "请求错误"),
    NOT_EXIST_DATA(4001, "数据不存在"),
    REQUEST_RETRY(4002, "操作失败，请重新操作"),
    INVALID_PARAMS(4003, "参数校验错误"),
    EMPTY_PARAMS(4004, "必要参数不能为空"),
    EMPTY_FILE(4005,"文件不能为空"),
    UNAUTHORIZED(5001, "尚未登录"),
    FORBIDDEN(5002, "您没有操作权限"),
    INVALID_TOKEN(5003, "INVALID TOKEN"),
    ERROR(5099, "服务器未知错误"),
    RUN_ERROR(5097, "系统出现错误，请重试"),
    /*系统级状态码*/
    DATABASE_DUPLICATEKEY(1001, "数据库中已存在该记录"),

    /**
     * 设备管理服务
     */
    NOT_FIND_OR_PERMISSION(7201, "没找到可用设备或没权限操作该设备"),
    IDENTIFIER_REQUIRED(7202, "标识符不能为空"),
    IDENTIFIER_NONSTANDARD(7203, "识别到不规范的标识符"),
    DATA_VERIFICATION_TIMEOUT(7204,"数据校验超时，请尝试缩减数据后分多次导入"),
    IMPORT_CHECK_ERROR(7205,"导入校验失败"),

    /**
     * 能力编排管理服务
     */
    NOT_WORKFLOW(7300, "流程数据不存在"),
    NOT_DEPLOY(7301, "该流程尚未部署"),
    NOT_PUBLISH(7302, "该流程尚未发布"),
    NOT_REPEAT_PUBLISH(7303, "不能重复发布"),
    FAILED_TASK(7304, "节点任务处理失败"),
    ERROR_TASK_FORMAR(7305, "解析节点任务失败"),

    /**
     * baop-mqtt 数据处理模块
     */
    ERROR_SUbSCRIBE(8001, "订阅失败"),
    ERROR_UNSUbSCRIBE(8002, "取消订阅失败"),
    ERROR_PUBLIC(8003, "发布订阅消息失败"),
    TABLE_ALREADY_EXIST(8004, "Table already exists"),
    FIEL_ALREADY_EXIST(8005, "fiel already exists"),
    ;

    private Integer code;
    private String message;

    StatusCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static StatusCode get(String message) {
        for (StatusCode responseStatusEnum : StatusCode.values()) {
            if (responseStatusEnum.getMessage() .equals(message)) {
                return responseStatusEnum;
            }
        }
        return null;
    }

    public static StatusCode get(int code) {
        for (StatusCode responseStatusEnum : StatusCode.values()) {
            if (responseStatusEnum.getCode() == code) {
                return responseStatusEnum;
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


    @Override
    public String toString() {
        return "StatusCode{" +
                "code=" + code +
                ", message='" + message + '\'' +
                '}';
    }
}
